package com.example.design_pattern.simple_factory;

import com.example.design_pattern.domain.Apple;
import com.example.design_pattern.domain.Banana;
import com.example.design_pattern.domain.Fruit;
import com.example.design_pattern.exception.ErrorFruitNameException;

/**
 * 工厂
 */
public class FruitFactory {

    public static Fruit createFruit(String catagory) throws ErrorFruitNameException {
        if("apple".equals(catagory)){
            return new Apple();
        }else if("banana".equals(catagory)){
            return new Banana();
        }else{
            throw new ErrorFruitNameException("无法生成该类别的产品：" + catagory);
        }
    }

}
